import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/home_chart_bean.dart';
import 'package:flutter/material.dart';
import '../bean/ui_const_bean.dart';
import 'circle_progress_widget.dart';
import 'work_head_widget.dart';
import '../bean/work_home_bean.dart';

class WorkSigleChartWidget extends StatelessWidget {

  final Function(HomeChartBean)  chartTap;
  final UpdateModuleListBean     updateModuleBean;
  final HomeChartBean            homeChartBean;

  double progress = 0.0;
  String firstTitle = '责任房源';
  String secondTitle = '已巡房';
  String firstAmount = '-';
  String secondAmount = '-';

  WorkSigleChartWidget(this.updateModuleBean,this.homeChartBean,this.chartTap);

  @override
  Widget build(BuildContext context) {
    if(homeChartBean!= null && homeChartBean.list.length > 0) {
        ChartBean  chartBean = homeChartBean.list[0];
        progress = chartBean.precentage;
        if(chartBean.items.length > 0) {
          for(int i = 0;i < 2;i++) {
            ChartItemBean item = chartBean.items[i];
            if(i == 0) {
              firstTitle = item.title;
              firstAmount = item.amount.toString();
            } else {
              secondAmount = item.amount.toString();
              secondTitle = item.title.toString();
            }
          }
      }
    }
    return buildedNewWidget(context);
  }

  Widget buildedNewWidget(BuildContext context) {
    return GestureDetector(
      child: Container(
        color: Colors.transparent,
        padding: const EdgeInsets.only(left: UIConstBean.LRSpace, right: UIConstBean.LRSpace,top: 10),
        child: Card(
          margin: EdgeInsets.only(bottom: 0),
          color: Colors.white,
          elevation: 0.0,
         clipBehavior: Clip.antiAliasWithSaveLayer,
          shape: const RoundedRectangleBorder(
            side: BorderSide.none,
            borderRadius: BorderRadius.all(Radius.circular(UIConstBean.CircularRadius),
            ),
          ),
          child: Container(
              padding: const EdgeInsets.only(left: UIConstBean.InnerLRSpace,right: UIConstBean.InnerLRSpace,top: UIConstBean.InnerTopSpace),
              color: Colors.white,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  WorkHeadWidget(itemHeadTap: null,title: updateModuleBean?.title,indicateType: HomeHeadTitleIndicateType.HomeHeadTitleIndicateLookAtType,),
                  SizedBox(height: 20,),
                  Row(
                    children: <Widget>[
                      SizedBox(width: 40,),
                      Container(
                        width: 100,
                        height: 100,
                        color: Colors.white,
                        padding:const  EdgeInsets.only(left: 0,top: 0),
                        child: Stack(
                          alignment: Alignment.center,
                          children: <Widget>[
                        RichText(text: TextSpan(
                          children: <TextSpan>[
                            TextSpan(text:'${(progress * 100).round()}',
                              style: TextStyle(fontSize: 28.0,
                              color: Color(0xff4a5261),fontWeight: FontWeight.w600,
                            ),
                            ),

                            TextSpan(text:'%',
                              style: TextStyle(fontSize: 12.0,
                                color: Color(0xff4a5261),fontWeight: FontWeight.w600,
                              ),
                            ),
                          ]
                        )
                        ),

                            CircleProgressWidget(
                              radius: 45.0,
                              ringColor: Color(0xffF1F1F1),
                              dotRadius: 4.0,
                              shadowWidth: 0.0,
                              progress: progress,
                              startColor: Color(0xff00E8B0),
                              endColor: Color(0xff1ACBD7),
                            ),
                          ],
                        ),
                      ),
                      SizedBox(width: 42,),
                      _buildChartContentWidget(),
                    ],
                  ),
                  SizedBox(height: 20,),
                ],
              )
          ),
        ),
      ),
      onTap: () {
        if(chartTap!= null) {
          chartTap(homeChartBean);
        }
      },
    );
  }

  Widget  _buildChartContentWidget() {
    return  Row(
      children: <Widget>[
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text(firstTitle,
              textAlign: TextAlign.left,
              style: TextStyle(fontSize: 13.0,
                color: Color(0xff666666),fontWeight: FontWeight.normal,
              ),
            ),
            SizedBox(height: 4,),
            Text(secondTitle,
              textAlign: TextAlign.left,
              style: TextStyle(fontSize: 13.0,
                color: Color(0xff666666),fontWeight: FontWeight.normal,
              ),
            ),
          ],
        ),

        Column(
          children: <Widget>[
            Text("  "+firstAmount,
              style: TextStyle(fontSize: 14.0,
                color: Color(0xff333333),fontWeight: FontWeight.bold,
              ),
            ),
            SizedBox(height: 4,),
            Text(secondAmount,
              style: TextStyle(fontSize: 14.0,
                color: Color(0xff333333),fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ],
    );
  }
}

